<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class Orders extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'order_number' => $this->order_number,
            'total_account' => $this->total_account,
            'total_amount' => $this->total_amount,
            'payment_method' => $this->payment_method,
            'paid_at' => (string)$this->paid_at,
            'created_at' => (string)$this->created_at,
            'status' => $this->status,
            'status_code' => $this->status_code,
            'status_comment' => $this->status_comment,
            'cancel_at' => $this->cancel_at, // 自动取消时间
            'items' => OrderItems::collection($this->items),
        ];
    }
}
